package com.od.controller;

import com.od.entity.Project;
import com.od.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("project")
@CrossOrigin
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    @RequestMapping("getProjectById")
    @ResponseBody
    public List<Project> getProjectById(int projectResume) {
        return projectService.getProjectById(projectResume);
    }

    @RequestMapping("addProject")
    @ResponseBody
    public int addProject(@RequestBody Project project) {
        System.out.println(project);
        return projectService.addProject(project);
    }

    @RequestMapping("updateProjectById")
    @ResponseBody
    public int updateProjectById(@RequestBody Project project) {
        System.out.println(project);
        return projectService.updateProjectById(project);
    }

    @RequestMapping("deleteProjectById")
    @ResponseBody
    public int deleteProjectById(@RequestBody Map<String, Integer> projectData) {
        int projectId = projectData.get("projectId");
        return projectService.deleteProjectById(projectId);
    }

}
